package org.ljx.taobao.controller;

import org.ljx.taobao.api.IUserService;
import org.ljx.taobao.api.entity.User;
import org.ljx.taobao.service.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author: Ljx
 * @Date: 2021/12/31 12:03
 * @role: 注销账号
 */
@WebServlet("/logout")
public class LogoutServlet extends HttpServlet {
    public static boolean x;
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setContentType("text/html;utf-8");
        String password = req.getParameter("password");
        User user = new User(LoginServlet.name1,password);
        IUserService iUserService = new UserServiceImpl();
        x = iUserService.delete(user);
        if (x){
            resp.sendRedirect("index.jsp");
        }else {
            req.setAttribute("msg","密码错误，注销失败！！！");
            req.getRequestDispatcher("logout.jsp").forward(req,resp);
        }
    }
}
